<template>
  <view :class="['KeyboarBody','bottomMove', 'bodMove', bodMove]" v-if="KeyboarHid">
    <view class="KeyboarBx">
      <view v-for="(num , index) in keyboardNum " :key='index'@tap.stop="" @touchstart="clickBoard(num[0])" hover-class="hover"
        :hover-stay-time='20' class="keyboar">
		<view class="">
			<view>{{num[0]}}</view>
			<view style="font-size: 16upx;">{{num[1]}}</view>
		</view>
      </view>
      <view @tap.stop="" class="keyboar empty" > </view>
      <view @tap.stop="" @touchstart="clickBoard('0')" hover-class="hover" :hover-stay-time='20' class="keyboar zero">0</view>
      <view @tap.stop="" @touchstart="deleteKeyboar()" class="keyboar keyboarflex" :hover-stay-time='20' hover-class="hover">
        <view class="keyboarDel"></view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
	props: {
		//限制输入框的长度 空值不限制
		psdLength: {
			type: [Number, String],
			default: ''
		},
		//键盘码
		keyboardNum: {
			type: [Array, Object],
			default: () => {
				return [[1], [2,'ABC'], [3,'DEF'], [4,'GHI'], [5,'JKL'], [6,'MNO'], [7,'PQRS'], [8,'TUV'], [9,'WXYZ']]
			},
			
		},
		value: {
			type: String,
			default: ''
		}
    },
    data() {
		return {
			bodMove: 'moveShow',
			password: '', //要返回的结果
			iptNum: [], //输入的内容
			KeyboarHid: true, //键盘影藏和显示
		}
	},
	watch: {
		iptNum(newVal, oldVal) {
			this.$emit('input', newVal.join(''))
		},
		value(newVal, oldVal) {
			this.iptNum = newVal.split('')
		}
	},
    methods: {
		open() {
			this.KeyboarHid = true;
			if (this.tabBar) {
				uni.hideTabBar()
			}
			this.$nextTick(() => {
				setTimeout(() => {
					this.bodMove = 'moveShow'
				}, 30)
			})
		},
		close() {
			if (this.tabBar) {
				uni.showTabBar()
			}
			this.bodMove = '';
			this.$nextTick(() => {
				setTimeout(() => {
					this.KeyboarHid = false
				}, 300)
			})
		},
		// 点击键盘
		clickBoard(num) {
			if (num == '') return;
			let iptNum = this.iptNum.filter(item => item != '');
			//判断是否限制长度
			if (this.psdLength != '') {
				if (iptNum.length >= this.psdLength) {
					return
				};
				this.iptNum.push(num);
			} else {
				this.iptNum.push(num);
			}
		},
		//重置 清空
		reset() {
			this.iptNum = [];
		},
		//删除
		deleteKeyboar() {
			this.iptNum.pop();
		}
	}
}
</script>

<style scoped>
  .bodMove {
    transition: all .3s
  }

  .bottomMove {
    bottom: 0;
    left: 0;
    width: 100%;
    transform: translateY(100%)
  }

  .moveShow {
    transform: translateY(0)
  }

  .KeyboarBody {
   /* position: fixed;
    bottom: 70upx;
    left: 0;
    right: 0;
    z-index: 99; */
    background-color: #D2D5DB;
	width: 90%;
	margin: 0 auto;
  }

  .KeyboarBx {
    display: flex;
    flex-wrap: wrap;
    text-align: center;
    padding: 10rpx 6rpx 0rpx 6rpx;
    margin-left: -12rpx;
  }

  .keyboar {
    width: 30%;
    flex-grow: 1;
    padding: 2upx 20upx;
    font-size: 40rpx;
    background-color: #FFFFFF;
    border-radius: 10rpx;
    margin-left: 12rpx;
    margin-bottom: 16rpx;
	min-height: 74upx;
	box-shadow: 0px 1px 1px #000;
  }
  .keyboar.zero{
	  line-height: 74upx;
  }

  .dian {
    margin-top: -10rpx;
  }

  .keyboarBtn {
    background: linear-gradient(45deg, rgba(242, 131, 9, 1) 0%, rgba(230, 36, 15, 1) 100%);
    color: #fff;
  }

  .hover {
    background: #ebedf0;
  }


  .bot {
    bottom: 0;
  }

  .empty {
    box-shadow: none;
	background-color: #fcfcfc;
  }

  .dowmImgBx {
    display: flex;
    justify-content: center;
    border-top: 1rpx solid A1A1A1;
  }

  .dowmImg {
    width: 35rpx;
    height: 35rpx;
    margin-bottom: 10rpx;
    background: url('');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 100%;
  }

  .keyboarDel {
    width: 50rpx;
    height: 36rpx;
    margin-bottom: 10rpx;
    background-image: url('');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 80%;
    margin-top: 11rpx;
  }

  .keyboarflex {
    display: flex;
    justify-content: center;
    align-items: center;
	box-shadow: none;
  }
</style>
